package com.jml.策略模式.重构if判断.service;


import com.jml.策略模式.重构if判断.StrategyContext;
import com.jml.策略模式.重构if判断.msg.strategy.MsgStrategy;
import com.jml.策略模式.重构if判断.pay.strategy.PayStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class MsgSerice {
    @Autowired
    private StrategyContext strategyContext;

    @GetMapping("/sendMsg")
    public String sendMsg(String strategyId, String phone) {
        MsgStrategy msgStrategy = strategyContext.getStrategy(strategyId, "send_msg", MsgStrategy.class);
        if (msgStrategy == null) {
            return "当前渠道已经关闭或者是不存在";
        }
        return msgStrategy.sendMsg(phone);
    }

    @GetMapping("/toPayHtml")
    public String toPayHtml(String strategyId) {
        PayStrategy payStrategy = strategyContext.getStrategy(strategyId, "pay", PayStrategy.class);
        if (payStrategy == null) {
            return "当前渠道已经关闭或者是不存在";
        }
        return payStrategy.toHtml();
    }
}
